51
Explore Your Deductive Logic—Sudoku
51
STEP 12 continued
Next k
If sbox(j, i) = ““ And cantbelistcount(j, i) = 7 Then
putnumberpresent(j, i) = ““
For putnumber = 1 To 9
If findincantbelist(putnumber, j, i) = 0 Then
putnumberpresent(j, i) = putnumberpresent(j, i) & putnumber
End If
Next putnumber
End If
For k = 1 To i - 1
If putnumberpresent(j, k) <> ““ And
putnumberpresent(j, k) = putnumberpresent(j, i) Then
For kk = 1 To k - 1
Call addtocantbelist(Mid(putnumberpresent(j, k), 1, 1), j, kk)
Call addtocantbelist(Mid(putnumberpresent(j, k), 2, 1), j, kk)
Next kk
For kk = k + 1 To i - 1
Call addtocantbelist(Mid(putnumberpresent(j, k), 1, 1), j, kk)
Call addtocantbelist(Mid(putnumberpresent(j, k), 2, 1), j, kk)
Next kk
For kk = i + 1 To 9
Call addtocantbelist(Mid(putnumberpresent(j, k), 1, 1), j, kk)
Call addtocantbelist(Mid(putnumberpresent(j, k), 2, 1), j, kk)
Next kk
Exit For
End If
Next k
Next j
Next i
STEP 13
The final step is to do the same for each 3 by 3 grid. We do not need to create the
putnumberpresent row again, since we have already built it. But it is a good idea to
refresh this list each time the cantbelist is updated.
For i = 1 To 9 Step 3
For j = 1 To 9 Step 3
For k = 1 To 3
n = Int((i - 1) / 3) * 3 + k
For l = 1 To 3
p = Int((j - 1) / 3) * 3 + l
For ka = 1 To 3
na = Int((i - 1) / 3) * 3 + ka
For la = 1 To 3
pa = Int((j - 1) / 3) * 3 + la
If n <> na Or p <> pa Then
If putnumberpresent(n, p) <> ““ And
putnumberpresent(n, p) = putnumberpresent(na, pa) Then